from flask import Blueprint, jsonify, request
from dao.housedao import HouseDao
from logger.logger import logger

datacontroller = Blueprint('datacontroller', __name__)

@datacontroller.route('/gethouseprice', methods=['GET', 'POST'])
def getHouseAvgPrice():
    # 方法接受的是AJAX请求
    houseDao = HouseDao()
    data = list(houseDao.statisticHouseAvgPrice())[:10]
    return jsonify(data)
    pass

@datacontroller.route('/gethouseinfra', methods=['GET', 'POST'])
def getInfrastuctureVersusPrice():
    # 方法接受的是AJAX请求
    houseDao = HouseDao()
    data = []
    data.append( houseDao.statsticInfrastuctureVersusPriceLT30())
    data.append( houseDao.statsticInfrastuctureVersusPrice30_60())
    data.append( houseDao.statsticInfrastuctureVersusPrice60_90())
    data.append( houseDao.statsticInfrastuctureVersusPrice90_120())
    data.append( houseDao.statsticInfrastuctureVersusPriceGT120())
    return jsonify(data)
    pass

@datacontroller.route('/gethouseareacount', methods=['GET', 'POST'])
def getHouseAreaNumber():
    # 方法接受的是AJAX请求
    houseDao = HouseDao()
    data = houseDao.statisticHouseArea();
    logger.info(data)
    return jsonify(data)
    pass
